[React 18] Fix cross-version compatibility and unit test errors#6994
[React 18] Fix cross-version compatibility and unit test errors#6994tkajtoch wants to merge 14 commits intoelastic:feature/react-18from
Conversation
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
2d13686 to
e5f68aa
Compare
3110b4c to
cf26cf3
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
|
@tkajtoch CI is still failing with a lint error it looks like: |
src/test/rtl/render_hook.ts
Outdated
| } else { | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| renderHook = require('@testing-library/react-hooks').renderHook; | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires |
There was a problem hiding this comment.
Let's just // eslint-disable @typescript-eslint/no-var-requires the entire file instead of having 4 separate comments, please!
Also oof, it's unfortunate that this is necessary - I'm curious as to what on earth changed in React 18 that hooks render differently compared in 17 🤦
There was a problem hiding this comment.
The change from import { render } from 'react-dom' to import { createRoot } from 'react-dom/client' caused all this :(
There was a problem hiding this comment.
Gotcha, thanks for clarifying!
There was a problem hiding this comment.
I wondered why // eslint-disable @typescript-eslint/no-var-requires didn't work for me yesterday... you have to use /* */ for multi-line disables instead 🤦🏻♂️
It's fixed now!
| cypressMount = require('@cypress/react').mount; | ||
| } | ||
|
|
||
| const mountCommand = (children: ReactNode): ReturnType<typeof mount> => { |
There was a problem hiding this comment.
@cee-chen I missed this when I was rebasing feature/react-18 a few days ago. The filename changed from mount.js to mount.tsx and I didn't catch your changes to reapply to the new file.
There was a problem hiding this comment.
Nice, thanks for catching that!
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
| export const testOnReactVersion = ( | ||
| versionOrVersions: ReactVersion | ReactVersion[] | ||
| ): typeof test => { | ||
| return isReactVersion(versionOrVersions) ? test : test.skip; |
There was a problem hiding this comment.
This is a super elegant util 👏 I wish I knew why that specific EuiOverlayMask test was failing though. Is this an RTL-specific issue that they might fix on their end later, or do we need to rewrite our test?
There was a problem hiding this comment.
I think it's connected to how React 18 RTL and jest interact and I hope it can be fixed on their end, we'll see when upgrading to the latest jest. It might also be related to throwing an error during a react component update that throws out react internals.
I tried wrapping <EuiOverlayMask aria-hidden={true} /> in class component with componentDidCatch, rendering it differently, moving the throw statement outside useEffect and none seemed to help.
I created #6998 to track this.
There was a problem hiding this comment.
Awesome, thanks so much for that info - that's super helpful!
There was a problem hiding this comment.
These are seriously fantastic test conversions - thanks for preferring RTL queries over snapshots as always!
caba775 to
3974d37
Compare
3974d37 to
71dc3e2
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
1 similar comment
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
1 similar comment
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
|
1 last test failure on CI!! |
| act(() => getByTestSubject('dataGridKeyboardShortcutsButton').click()); | ||
| rerender(<>{result.current.keyboardShortcuts}</>); | ||
| renderHookAct(() => | ||
| getByTestSubject('dataGridKeyboardShortcutsButton').click() |
There was a problem hiding this comment.
So, unfortunately this test is no longer working/outputting the expected DOM element - the snapshot is missing the portal content.
Can you try using fireEvent.click here instead of .click()?
There was a problem hiding this comment.
Great catch, thank you!
| }); | ||
|
|
||
| afterAll(() => { | ||
| consoleErrorOverride.mockRestore(); |
There was a problem hiding this comment.
This looks fantastic, thanks so much for making this change!
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
|
jenkins test this |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/ |
cee-chen
left a comment
There was a problem hiding this comment.
🎉 Hopefully Jenkins doesn't lose its mind this time and CI finally passes green!
|
jenkins test this please |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/ |
Summary
This PR fixes all remaining unit tests, adds cross-version compatibility to useRenderToText() and fixes code style in a few files I missed that were merged before (sorry!!)
QA
rm -rf node_modules && yarnyarn lintyarn test-unitREACT_VERSION=17 yarn test-unit